var index = 1;
var entries = Array(5);
var blockInsert = false;

$(document).ready(function(){
  $("#enableNetwork").change(function(){
    if($(this).is(":checked"))
      $('.networkinput').removeAttr("disabled");
    else
      $('.networkinput').attr("disabled","disabled");
  });
});

function changeDHCPNetField(input)
{  
  var $textfield=$(input);
  if($textfield.val() !== "")
  {
    if($textfield.closest('tr').next('.line').length <= 0)
    {
      $textfield.closest('tbody').append('<tr class="line"><td><input type="text" name="dhcpnet['+index+']" onchange="changeDHCPNetField(this)" value="" size="15" /></td><td></td></tr>');
      index++;
    }
  }
  else
  {
    $textfield.closest('tr').remove();
    $textfield.remove();
  }
}

function insertTextField(td,name,index) { // td = table data
   var text = td.innerHTML;// text speichern für Textfeld
  if(text.indexOf('<input name=')===-1 && blockInsert === false) //if contains substring
  {
    entries[index]=text;
    td.innerHTML = ""; // Inhalt des <td>-Tags löschen
    var inner = "";
      inner = '<input name="'+name+'" type="text" value="' + text + '" />';
    
    inner+='<input type="button" value="Abbruch" name="abort" onclick="DeleteTextField(this.parentNode,'+index+')" />';

    td.innerHTML = inner;
  }
  else
    blockInsert=false;
}

function DeleteTextField(td,index)
{
  td.innerHTML=entries[index];
  blockInsert=true;
}

function deleteNet(td,net)
{
  if(confirm("DHCP Netz wirklich löschen?"))
  {
    td.innerHTML='<img src="../design/pictures/loading.gif" width="20px" alt="..." />';

   $.post("ajax/removeDHCPNet.php",{"net":net}).done(function(data)
   {
     if(data==="true")
     {$(td).closest('tr').fadeTo(400,0,function(){$(this).remove();});}
   });   
  }
}